package com.zkh.myutils.database.enums;

/**
 * 数据库查询的条件
 * @author zkh
 *
 */
public enum Symbol {
	/**
	 * 大于
	 */
	GT("gt", ">", 1),
	/**
	 * 小于
	 */
	LT("lt", "<", 2),
	/**
	 * 大于等于
	 */
	GE("ge", ">=", 3),
	/**
	 * 小于等于
	 */
	LE("le", "<=", 4),
	/**
	 * between条件
	 */
	BETWEEN("between", " between ", 5),
	/**
	 * in条件
	 */
	IN("in", " in", 6),
	/**
	 * not in 条件
	 */
	NOTIN("notin", " not in", 7),
	/**
	 * 不等于
	 */
	NE("ne", "!=", 8),
	/**
	 * 等于
	 */
	EQ("eq", "=", 9),
	/**
	 * like条件
	 */
	LIKE("like", " like ", 10),
	/**
	 * 为null
	 */
	NULL("null", " is null ", 11),
	/**
	 * 不为null
	 */
	NOTNULL("notnull", " is not null ", 12),
	/**
	 * 逻辑与
	 */
	AND("and", " and ", 13),
	/**
	 * 逻辑或
	 */
	OR("or", " or ", 14),
	/**
	 * 没有值
	 */
	NOVALUE("novalue", "no value", 15),
	/**
	 * 存在
	 */
	EXISTS("exists", " exists", 16),
	/**
	 * 不存在
	 */
	NOTEXISTS("notexists", " not exists", 17),
	/**
	 * not between条件
	 */
	NOTBETWEEN("notbetween", " not between ", 18),
	/**
	 * not like条件
	 */
	NOTLIKE("notlike", " not like ", 19),
	/**
	 * 空
	 */
	EMPTY("", "", 99);
	
	//属性
	public String name;
	public String symbol;
	public int index;
	//构造方法
	private Symbol(String name, String symbol, int index){
		this.name = name;
		this.symbol = symbol;
		this.index = index;
	}
	@Override
	public String toString() {
		return "Symbols [name=" + name + ", index=" + index + "]";
	}
	//根据名称返回对象
	public static Symbol getSymbol(String name){
		//遍历
		for(Symbol s: Symbol.values()){
			if(s.name.equals(name)){
				return s;
			}
		}
		//未找到
		return null;
	}
	//根据索引返回对象
	public static Symbol getSymbol(int index){
		//遍历
		for(Symbol s: Symbol.values()){
			if(s.index==index){
				return s;
			}
		}
		//未找到
		return null;
	}
}
